 /*******************************************************************************
 * Package: com.hngtrust.iir.third.controller
 * Type:    ChinaTrustRegistrationController
 * Date:    2021/10/14 10:26
 *
 * Copyright (c) 2021 HUANENG GUICHENG TRUST CORP.,LTD All Rights Reserved.
 *
 * You may not use this file except in compliance with the License.
 *******************************************************************************/
package com.hngtrust.iir.third.controller;

import com.hngtrust.framework.page.PageResult;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.hngtrust.framework.bind.ResponseInfo;
import com.hngtrust.iir.dto.ReqDTO;
import com.hngtrust.iir.third.controller.dto.CtrRelationDTO;
import com.hngtrust.iir.third.controller.dto.RelatedPartiesExportVO;
import com.hngtrust.iir.third.controller.dto.RelatedPartiesVO;
import com.hngtrust.iir.third.service.RelatedPartiesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;

/**
 * 调用中信登第三方接口(关联方信息)
 *
 * @author Yujiaqi
 * @date 2021/10/14 10:26
 */

@Slf4j
@RestController
@RequestMapping("/related_parties")
@Api(tags = "调用中信登第三方接口(关联方信息)")
public class RelatedPartiesController {
    
    @Autowired
    private RelatedPartiesService relatedPartiesService;
    
    @ApiOperation(value = "关联方信息查询", notes = "关联方信息查询")
    @PostMapping("/query-related_parties")
    public ResponseInfo<PageResult<CtrRelationDTO>> addRelatedParties(
            @ApiParam("关联方信息查询请求参数") @Valid @RequestBody ReqDTO<RelatedPartiesVO> relatedPartiesVO) throws JsonProcessingException {
        log.info("RelatedPartiesController.relatedParties start...");
        return relatedPartiesService.addRelatedParties(relatedPartiesVO);
    }
    
    @ApiOperation(value = "更新中信登受益人数据", notes = "更新中信登受益人数据")
    @PostMapping("/update-related_parties")
    public ResponseInfo<PageResult<CtrRelationDTO>> updateRelatedParties(
            @ApiParam("关联方信息查询请求参数") @Valid @RequestBody ReqDTO<RelatedPartiesVO> relatedPartiesVO) throws JsonProcessingException {
        log.info("RelatedPartiesController.updateRelatedParties start...");
        return relatedPartiesService.updateRelatedParties(relatedPartiesVO);
    }
    
    @ApiOperation(value = "关联方数据导出", notes = "关联方数据导出")
    @PostMapping("/data-export")
    public void dataExport(
            @ApiParam("受益人请求参数") @Valid @RequestBody RelatedPartiesExportVO relatedPartiesExportVO, HttpServletResponse response)
            throws IOException {
        log.info("RelatedPartiesController.dataExport start...");
        relatedPartiesService.dataExport(relatedPartiesExportVO,response);
    }
    
}
